package com.zh.note.huawei.onehundred.阿里巴巴找黄金宝箱;

/**
 * https://dream.blog.csdn.net/article/details/130837717
 */
public class Main {
    public static void main(String[] args) {
        // Scanner sc = new Scanner(System.in);
        // String input = sc.nextLine();
        String input = "2,5,-1,8,6";
        String[] split = input.split(",");
        int[] nums = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            nums[i] = Integer.parseInt(split[i]);

        }
        int res = solution(nums);
        System.out.println(res);

    }

    private static int solution(int[] nums) {

        int leftSum = 0;
        int rightSum = 0;
        for (int i = 0; i < nums.length; i++) {
            rightSum += nums[i];
        }
        for (int i = 0; i < nums.length; i++) {
            rightSum -= nums[i];
            if (leftSum == rightSum) {
                return i;
            }
            leftSum += nums[i];
        }
        return -1;
    }
}
